﻿using Dict.Config;
using System;
using System.Collections.Generic;
using Dict.DataModel;

namespace Battle.Engine.LogicModel
{
    public class BuffOfPropertyTransfer : Buff {
        
        public override Buff Clone()
        {
            var newBuff = base.Clone() as BuffOfPropertyTransfer;
            return newBuff;
        }
        public override void Init(TableBuff tableBuff, EngineData engineData)
        {
            base.Init(tableBuff, engineData);
        }

        public override void LoadBuff0()
        {
            
        }

        public override void UnloadBuff0()
        {
            
        }

        public override void Effect()
        {
            switch (this.factor)
            {
                case TableFactorConst.perhpTodamageAdd:
                    //每降低百分比args1的血量，增加百分比args2的伤害，最多加args3
                    double perhpTodamageAddRatio = (this.buffTargetActor.attribute.hp / this.buffTargetActor.attribute.maxHp - 1) / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.damageAdd;
                    this.val = this.args2 * Math.Floor(perhpTodamageAddRatio);
                    if (this.args3 != 0 && this.val < this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.damageAdd += this.val;
                    break;
                case TableFactorConst.perhpTodamageReduce:
                    //每降低百分比args1的血量，减少百分比args2的免伤，最多减args3
                    double perhpTodamageReduceRatio = (this.buffTargetActor.attribute.hp / this.buffTargetActor.attribute.maxHp - 1) / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.damageReduce;
                    this.val = this.args2 * Math.Floor(perhpTodamageReduceRatio);
                    if (this.args3 != 0 && this.val < this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.damageReduce += this.val;
                    break;
                case TableFactorConst.perhpToheal:
                    //每降低百分比args1的血量，增加args2的被治疗量，最多加args3
                    double perhpTohealRatio = (this.buffTargetActor.attribute.hp / this.buffTargetActor.attribute.maxHp - 1) / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.heal;
                    this.val = this.args2 * Math.Floor(perhpTohealRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.buffTargetActor.attribute.heal += this.val;
                    break;
                case TableFactorConst.perhpTododge:
                    //每降低百分比args1的血量，增加百分比args2的闪避，最多加args3
                    double perhpTododgeRatio = (this.buffTargetActor.attribute.hp / this.buffTargetActor.attribute.maxHp - 1) / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.dodge;
                    this.val = this.args2 * Math.Floor(perhpTododgeRatio); 
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.dodge += this.val;
                    break;
                case TableFactorConst.perhpTocri:
                    //每降低百分比args1的血量，增加百分比args2的暴击，最多加args3
                    double perhpTocriRatio = (this.buffTargetActor.attribute.hp / this.buffTargetActor.attribute.maxHp - 1) / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.cri;
                    this.val = this.args2 * Math.Floor(perhpTocriRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.cri += this.val;
                    break;
                case TableFactorConst.perhpTodef:
                    //每降低百分比args1的血量，增加args2的防御，最多加args3
                    double perhpTodefRatio = (this.buffTargetActor.attribute.hp / this.buffTargetActor.attribute.maxHp - 1) / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.def;
                    this.val = this.args2 * Math.Floor(perhpTodefRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.buffTargetActor.attribute.pdef.AddIncrement(this.val);
                    this.buffTargetActor.attribute.mdef.AddIncrement(this.val);
                    break;
                case TableFactorConst.perhpToperdef:
                    //每降低百分比args1的血量，增加百分比args2的暴击，最多加args3
                    double perhpToperdefRatio = (this.buffTargetActor.attribute.hp / this.buffTargetActor.attribute.maxHp - 1) / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.def;
                    this.val = this.args2 * Math.Floor(perhpToperdefRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.pdef.AddRate(this.val);
                    this.buffTargetActor.attribute.mdef.AddRate(this.val);
                    break;
                case TableFactorConst.comboNumTocri:
                    //每增加args1的连击数，增加args2的暴击率，最多加args3
                    double comboNumTocriRatio = this.buffTargetActor.player.comboNum / this.args1;
                    this.type = TableFactorConst.cri;
                    this.val = this.args2 * Math.Floor(comboNumTocriRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.cri += this.val;
                    break;
                case TableFactorConst.angerToperatt:
                    //每增加args1的能量，增加args2的攻击百分比，最多加args3
                    double angerToperattRatio = this.buffTargetActor.player.angerNum / this.args1;
                    this.type = TableFactorConst.peratt;
                    this.val = this.args2 * Math.Floor(angerToperattRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.att.AddRate(this.val);
                    break;
                case TableFactorConst.angerTocri:
                    //每增加args1的能量，增加args2的暴击率，最多加args3
                    double angerTocriRatio = this.buffTargetActor.player.angerNum / this.args1;
                    this.type = TableFactorConst.cri;
                    this.val = this.args2 * Math.Floor(angerTocriRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.cri += this.val;
                    break;
                case TableFactorConst.angerTododge:
                    //每增加args1的能量，增加args2的闪避率，最多加args3
                    double angerTododgeRatio = this.buffTargetActor.player.angerNum / this.args1;
                    this.type = TableFactorConst.dodge;
                    this.val = this.args2 * Math.Floor(angerTododgeRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.dodge += this.val;
                    break;
                case TableFactorConst.sourceperattToshield:
                    this.type = TableFactorConst.shield;
                    this.val = this.buffOrigion.GetSourceActor().attribute.att.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.shield += this.val;
                    break;
                case TableFactorConst.sourceperattTopshield:
                    this.type = TableFactorConst.pshield;
                    this.val = this.buffOrigion.GetSourceActor().attribute.att.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.pshield += this.val;
                    break;
                case TableFactorConst.sourceperattTomshield:
                    this.type = TableFactorConst.mshield;
                    this.val = this.buffOrigion.GetSourceActor().attribute.att.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.mshield += this.val;
                    break;
                case TableFactorConst.sourceNhitToperdef:
                    this.type = TableFactorConst.def;
                    this.val = this.buffOrigion.GetSourceActor().attribute.hit * this.args1;
                    this.buffTargetActor.attribute.mdef.AddRate(this.val);
                    this.buffTargetActor.attribute.pdef.AddRate(this.val);
                    break;
                case TableFactorConst.perlevelTohit:
                    this.type = TableFactorConst.hit;
                    this.val = this.buffTargetActor.player.level * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.hit += this.val;
                    break;
                case TableFactorConst.perlevelTododge:
                    this.type = TableFactorConst.dodge;
                    this.val = this.buffTargetActor.player.level * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.dodge += this.val;
                    break;
                case TableFactorConst.perattTodef:
                    this.type = TableFactorConst.def;
                    this.val = this.buffTargetActor.player.level * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.pdef.AddIncrement(this.val);
                    this.buffTargetActor.attribute.mdef.AddIncrement(this.val);
                    break;
                case TableFactorConst.sourceperattToatt:
                    this.type = TableFactorConst.att;
                    this.val = this.buffOrigion.GetSourceActor().attribute.att.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.att.AddIncrement(this.val);
                    break;
                case TableFactorConst.sourceperdefTodef:
                    this.type = TableFactorConst.def;
                    this.val = this.buffOrigion.GetSourceActor().attribute.pdef.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.pdef.AddIncrement(this.val);
                    this.val2 = this.buffOrigion.GetSourceActor().attribute.mdef.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.mdef.AddIncrement(this.val2);
                    break;
                case TableFactorConst.sourceperpdefTopdef:
                    this.type = TableFactorConst.pdef;
                    this.val = this.buffOrigion.GetSourceActor().attribute.pdef.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.pdef.AddIncrement(this.val);
                    break;
                case TableFactorConst.sourcepermdefTomdef:
                    this.type = TableFactorConst.mdef;
                    this.val = this.buffOrigion.GetSourceActor().attribute.mdef.value * this.args1 * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.mdef.AddIncrement(this.val);
                    break;
                case TableFactorConst.angerToperdef:
                    //每增加args1的能量，增加args2的防御百分比，最多加args3
                    double angerToperdefRatio = this.buffTargetActor.player.angerNum / this.args1;
                    this.type = TableFactorConst.perdef;
                    this.val = this.args2 * Math.Floor(angerToperdefRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.pdef.AddRate(this.val);
                    this.buffTargetActor.attribute.mdef.AddRate(this.val);
                    break;
                case TableFactorConst.angerToperpdef:
                    //每增加args1的能量，增加args2的物理防御百分比，最多加args3
                    double angerToperpdefRatio = this.buffTargetActor.player.angerNum / this.args1;
                    this.type = TableFactorConst.perpdef;
                    this.val = this.args2 * Math.Floor(angerToperpdefRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.pdef.AddRate(this.val);
                    break;
                case TableFactorConst.angerTopermdef:
                    //每增加args1的能量，增加args2的物理防御百分比，最多加args3
                    double angerTopermdefRatio = this.buffTargetActor.player.angerNum / this.args1;
                    this.type = TableFactorConst.permdef;
                    this.val = this.args2 * Math.Floor(angerTopermdefRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.mdef.AddRate(this.val);
                    break;
                case TableFactorConst.MangerToNperhp:
                    this.type = TableFactorConst.hp;
                    this.buffTargetActor.attribute.angerTohpAF += (int)this.args1;
                    this.buffTargetActor.attribute.angerTohpHF += this.args2 * CommonMethod.tableAttributeConvert * this.buffTargetActor.attribute.maxHp;
                    break;
                case TableFactorConst.MperhpreduceToNanger:
                    this.type = TableFactorConst.anger;
                    this.buffTargetActor.attribute.perhpreduceToangerHF += this.args1 * CommonMethod.tableAttributeConvert * this.buffTargetActor.attribute.maxHp;
                    this.buffTargetActor.attribute.perhpreduceToangerAF += (int)this.args2;
                    break;
                case TableFactorConst.breachedLevelTododge:
                    //每增加args1的突破等级，增加args2的闪避，最多加args3
                    double breachedLevelTododgeRatio = this.buffTargetActor.breachedLevel / this.args1;
                    this.type = TableFactorConst.dodge;
                    this.val = this.args2 * Math.Floor(breachedLevelTododgeRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.dodge += this.val;
                    break;
                case TableFactorConst.criTododge:
                    //暴击提升闪避
                    double criTododgeRatio = this.buffTargetActor.attribute.cri / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.dodge;
                    this.val = this.args2 * Math.Floor(criTododgeRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.dodge += this.val;
                    break;
                case TableFactorConst.criTocriFactor:
                    //暴击提升暴击系数
                    double criTocriFactorRatio = this.buffTargetActor.attribute.cri / (this.args1 * CommonMethod.tableAttributeConvert);
                    this.type = TableFactorConst.criFactor;
                    this.val = this.args2 * Math.Floor(criTocriFactorRatio);
                    if (this.args3 != 0 && this.val > this.args3)
                    {
                        this.val = this.args3;
                    }
                    this.val = this.val * CommonMethod.tableAttributeConvert;
                    this.buffTargetActor.attribute.criFactor += this.val;
                    break;
                default:
                    break;

            }
        }

        public override void UnEffect()
        {
            switch (this.factor)
            {
                case TableFactorConst.perhpTodamageAdd:
                    this.buffTargetActor.attribute.damageAdd -= this.val;
                    break;
                case TableFactorConst.perhpTodamageReduce:
                    this.buffTargetActor.attribute.damageReduce -= this.val;
                    break;
                case TableFactorConst.perhpToheal:
                    this.buffTargetActor.attribute.heal -= this.val;
                    break;
                case TableFactorConst.perhpTododge:
                    this.buffTargetActor.attribute.dodge -= this.val;
                    break;
                case TableFactorConst.perhpTocri:
                    this.buffTargetActor.attribute.cri -= this.val;
                    break;
                case TableFactorConst.perhpTodef:
                    this.buffTargetActor.attribute.pdef.AddIncrement(-this.val);
                    this.buffTargetActor.attribute.mdef.AddIncrement(-this.val);
                    break;
                case TableFactorConst.perhpToperdef:
                    this.buffTargetActor.attribute.pdef.AddRate(-this.val);
                    this.buffTargetActor.attribute.mdef.AddRate(-this.val);
                    break;
                case TableFactorConst.comboNumTocri:
                    this.buffTargetActor.attribute.cri -= this.val;
                    break;
                case TableFactorConst.angerToperatt:
                    this.buffTargetActor.attribute.att.AddRate(-this.val);
                    break;
                case TableFactorConst.angerTocri:
                    this.buffTargetActor.attribute.cri -= this.val;
                    break;
                case TableFactorConst.angerTododge:
                    this.buffTargetActor.attribute.dodge -= this.val;
                    break;
                case TableFactorConst.sourceperattToshield:
                    this.buffTargetActor.attribute.shield = 0;//血盾是覆盖性buff
                    break;
                case TableFactorConst.sourceperattTopshield:
                    this.buffTargetActor.attribute.pshield = 0;//血盾是覆盖性buff
                    break;
                case TableFactorConst.sourceperattTomshield:
                    this.buffTargetActor.attribute.mshield = 0;//血盾是覆盖性buff
                    break;
                case TableFactorConst.sourceNhitToperdef:
                    this.buffTargetActor.attribute.mdef.AddRate(-this.val);
                    this.buffTargetActor.attribute.pdef.AddRate(-this.val);
                    break;
                case TableFactorConst.perlevelTohit:
                    this.buffTargetActor.attribute.hit -= this.val;
                    break;
                case TableFactorConst.perlevelTododge:
                    this.buffTargetActor.attribute.dodge -= this.val;
                    break;
                case TableFactorConst.perattTodef:
                    this.buffTargetActor.attribute.pdef.AddIncrement(-this.val);
                    this.buffTargetActor.attribute.mdef.AddIncrement(-this.val);
                    break;
                case TableFactorConst.sourceperattToatt:
                    this.buffTargetActor.attribute.att.AddIncrement(-this.val);
                    break;
                case TableFactorConst.sourceperdefTodef:
                    this.buffTargetActor.attribute.pdef.AddIncrement(-this.val);
                    this.buffTargetActor.attribute.mdef.AddIncrement(-this.val2);
                    break;
                case TableFactorConst.sourceperpdefTopdef:
                    this.buffTargetActor.attribute.pdef.AddIncrement(-this.val);
                    break;
                case TableFactorConst.sourcepermdefTomdef:
                    this.buffTargetActor.attribute.mdef.AddIncrement(-this.val);
                    break;
                case TableFactorConst.angerToperdef:
                    this.buffTargetActor.attribute.pdef.AddRate(-this.val);
                    this.buffTargetActor.attribute.mdef.AddRate(-this.val);
                    break;
                case TableFactorConst.angerToperpdef:
                    this.buffTargetActor.attribute.pdef.AddRate(-this.val);
                    break;
                case TableFactorConst.angerTopermdef:
                    this.buffTargetActor.attribute.mdef.AddRate(-this.val);
                    break;
                case TableFactorConst.MangerToNperhp:
                    this.buffTargetActor.attribute.angerTohpAF -= (int)this.args1;
                    this.buffTargetActor.attribute.angerTohpHF -= this.args2 * CommonMethod.tableAttributeConvert * this.buffTargetActor.attribute.maxHp;
                    break;
                case TableFactorConst.MperhpreduceToNanger:
                    this.buffTargetActor.attribute.perhpreduceToangerHF -= this.args1 * CommonMethod.tableAttributeConvert * this.buffTargetActor.attribute.maxHp;
                    this.buffTargetActor.attribute.perhpreduceToangerAF -= (int)this.args2;
                    break;
                case TableFactorConst.breachedLevelTododge:
                    this.buffTargetActor.attribute.dodge -= this.val;
                    break;
                case TableFactorConst.criTododge:
                    this.buffTargetActor.attribute.dodge -= this.val;
                    break;
                case TableFactorConst.criTocriFactor:
                    this.buffTargetActor.attribute.criFactor -= this.val;
                    break;
                default:
                    break;
            }
        }


    }
}
